using System;
using System.Collections;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;

using WHC.Pager.Entity;
using Microsoft.Practices.EnterpriseLibrary.Data;
using WHC.Hotel.Entity;
using WHC.Hotel.IDAL;
using WHC.OrderWater.Commons;

namespace WHC.Hotel.DAL
{
	/// <summary>
	/// TeaBook 的摘要说明。
	/// </summary>
	public class KTVBook : BaseDAL<KTVBookInfo>, IKTVBook
	{
		#region 对象实例及构造函数

		public static KTVBook Instance
		{
			get
			{
				return new KTVBook();
			}
		}
		public KTVBook() : base("YL_KTVBook","ID")
		{
		}

		#endregion

		/// <summary>
		/// 将DataReader的属性值转化为实体类的属性值，返回实体类
		/// </summary>
		/// <param name="dr">有效的DataReader对象</param>
		/// <returns>实体类对象</returns>
		protected override KTVBookInfo DataReaderToEntity(IDataReader dataReader)
		{
			KTVBookInfo teaBookInfo = new KTVBookInfo();
			SmartDataReader reader = new SmartDataReader(dataReader);
			
			teaBookInfo.ID = reader.GetInt32("ID");
			teaBookInfo.RoomNo = reader.GetString("RoomNo");
			teaBookInfo.BookNo = reader.GetString("BookNo");
			teaBookInfo.IsCancel = reader.GetBoolean("IsCancel");
			teaBookInfo.CustomerName = reader.GetString("CustomerName");
			teaBookInfo.CustomerTel = reader.GetString("CustomerTel");
			teaBookInfo.PreArrivalTime = reader.GetDateTime("PreArrivalTime");
			teaBookInfo.PreOffTime = reader.GetDateTime("PreOffTime");
			teaBookInfo.RetentionTime = reader.GetDateTime("RetentionTime");
			teaBookInfo.Note = reader.GetString("Note");
			
			return teaBookInfo;
		}

		/// <summary>
		/// 将实体对象的属性值转化为Hashtable对应的键值
		/// </summary>
		/// <param name="obj">有效的实体对象</param>
		/// <returns>包含键值映射的Hashtable</returns>
        protected override Hashtable GetHashByEntity(KTVBookInfo obj)
		{
		    KTVBookInfo info = obj as KTVBookInfo;
			Hashtable hash = new Hashtable(); 
			
 			hash.Add("RoomNo", info.RoomNo);
 			hash.Add("BookNo", info.BookNo);
 			hash.Add("IsCancel", info.IsCancel);
 			hash.Add("CustomerName", info.CustomerName);
 			hash.Add("CustomerTel", info.CustomerTel);
 			hash.Add("PreArrivalTime", info.PreArrivalTime);
 			hash.Add("PreOffTime", info.PreOffTime);
 			hash.Add("RetentionTime", info.RetentionTime);
 			hash.Add("Note", info.Note);
 				
			return hash;
		}


        public bool UpdateBookIn(int id, bool isCancel)
        {
            string sql = string.Format("update {0} set IsCancel={1} where ID ={2}",
                tableName, isCancel ? 1 : 0, id);
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand command = db.GetSqlStringCommand(sql);
            return db.ExecuteNonQuery(command) > 0;
        }
    }
}